package com.ktgj.service.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.service.domain.KtserviceViphallPartner;
import com.ktgj.service.service.IKtserviceViphallPartnerService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 合作商（供应商和代理商）Controller
 * 
 * @author ruoyi
 * @date 2021-09-06
 */
@ControllerAdvice
@RestController
@RequestMapping("/partner")
public class KtserviceViphallPartnerController extends BaseController
{
    @Autowired
    private IKtserviceViphallPartnerService KtserviceViphallPartnerService;

    /**
     * 查询合作商（供应商和代理商）列表
     */
    @PreAuthorize(hasPermi = "service:partner:list")
    @GetMapping("/list")
    public TableDataInfo list(KtserviceViphallPartner KtserviceViphallPartner)
    {
        startPage();
        List<KtserviceViphallPartner> list = KtserviceViphallPartnerService.selectKtserviceViphallPartnerList(KtserviceViphallPartner);
        return getDataTable(list);
    }

    /**
     * 导出合作商（供应商和代理商）列表
     */
    @PreAuthorize(hasPermi = "service:partner:export")
    @Log(title = "合作商（供应商和代理商）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KtserviceViphallPartner KtserviceViphallPartner) throws IOException
    {
        List<KtserviceViphallPartner> list = KtserviceViphallPartnerService.selectKtserviceViphallPartnerList(KtserviceViphallPartner);
        ExcelUtil<KtserviceViphallPartner> util = new ExcelUtil<KtserviceViphallPartner>(KtserviceViphallPartner.class);
        util.exportExcel(response, list, "合作商（供应商和代理商）数据");
    }

    /**
     * 获取合作商（供应商和代理商）详细信息
     */
    @PreAuthorize(hasPermi = "service:partner:query")
    @GetMapping(value = "/{partnerId}")
    public AjaxResult getInfo(@PathVariable("partnerId") Long partnerId)
    {
        return AjaxResult.success(KtserviceViphallPartnerService.selectKtserviceViphallPartnerById(partnerId));
    }

    /**
     * 新增合作商（供应商和代理商）
     */
    @PreAuthorize(hasPermi = "service:partner:add")
    @Log(title = "合作商（供应商和代理商）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KtserviceViphallPartner KtserviceViphallPartner)
    {
        return toAjax(KtserviceViphallPartnerService.insertKtserviceViphallPartner(KtserviceViphallPartner));
    }

    /**
     * 修改合作商（供应商和代理商）
     */
    @PreAuthorize(hasPermi = "service:partner:edit")
    @Log(title = "合作商（供应商和代理商）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KtserviceViphallPartner KtserviceViphallPartner)
    {
        return toAjax(KtserviceViphallPartnerService.updateKtserviceViphallPartner(KtserviceViphallPartner));
    }

    /**
     * 删除合作商（供应商和代理商）
     */
    @PreAuthorize(hasPermi = "service:partner:remove")
    @Log(title = "合作商（供应商和代理商）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partnerIds}")
    public AjaxResult remove(@PathVariable Long[] partnerIds)
    {
        return toAjax(KtserviceViphallPartnerService.deleteKtserviceViphallPartnerByIds(partnerIds));
    }
}
